﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Erebos
{
    enum CharackterKlasse
    {
        Mensch = 0,
        Babar = 16,
        Vampir = 32,
        Echsenmensch = 64,
        Zwerg = 80,
        Werwolf = 96,
        Katzenmensch = 112,
        Dunkelelf = 128,
        Erebos = 144
    }

    enum CharackterJob
    {
        Magier = 1,
        Assasine = 2,
        Barde = 3,
        Jäger = 4,
        Späher = 5,
        Wächter = 6,
        Ritter = 7,
        Dieb = 8,
        Hexenmeister = 9
    }

    enum RightsE
    {
        Voll = 2,
        Eingeschränkt = 1,
        Kein = 0
    }

    struct Rights
    {
        public RightsE AllowChat;
        public RightsE AllowGiveQuest;
        public RightsE AllowWarning;
        public RightsE AllowBann;
        public RightsE AllowConsole;

        public Rights(RightsE allowChat, RightsE allowGiveQuest, RightsE allowWarning, RightsE allowBann, RightsE allowConsole)
        {
            AllowChat = allowChat;
            AllowGiveQuest = allowGiveQuest;
            AllowWarning = allowWarning;
            AllowBann = allowBann;
            AllowConsole = allowConsole;
        }

        public override string ToString()
        {
            if (AllowChat == RightsE.Kein && AllowGiveQuest == RightsE.Kein && AllowWarning == RightsE.Kein && AllowBann == RightsE.Kein && AllowConsole == RightsE.Kein)
                return "0";
            else
                return "" + (int)AllowChat + "" + (int)AllowGiveQuest + "" + (int)AllowWarning + "" + (int)AllowBann + "" + (int)AllowConsole;
        }
    }

    class Charackter
    {
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private int _level;
        public int Level
        {
            get { return _level; }
            set { _level = value; }
        }

        private CharackterKlasse _klasse;
        public CharackterKlasse Klasse
        {
            get { return _klasse; }
            set { _klasse = value; }
        }

        private CharackterJob _job;
        public CharackterJob Job
        {
            get { return _job; }
            set { _job = value; }
        }

        private Rights _rights;
        public Rights Rights
        {
            get { return _rights; }
            set { _rights = value; }
        }

        private int _mindex;
        public int MapIndex
        {
            get { return _mindex; }
            set { _mindex = value; }
        }

        private RightsE HelpRightsE(char c)
        {
            if (c == '0')
                return RightsE.Kein;
            if (c == '1')
                return RightsE.Eingeschränkt;
            if (c == '2')
                return RightsE.Voll;

            return RightsE.Kein;
        }

        public Charackter(string name, int level, int charcode, string rights, int mindex)
        {
            _name = name;
            _level = level;
            _mindex = mindex;

            //Charackterklassen (9)
            for (int klasse = 0; klasse <= 144; klasse += 16)
                //Jobs (9)
                for (int job = 1; job <= 9; job++)
                    if (charcode == klasse + job)
                    {
                        _klasse = (CharackterKlasse)klasse;
                        _job = (CharackterJob)job;
                    }

            if (rights.Length == 1)
                _rights = new Rights((RightsE)Convert.ToInt32(rights[0]), (RightsE)Convert.ToInt32(rights[0]), (RightsE)Convert.ToInt32(rights[0]), (RightsE)Convert.ToInt32(rights[0]), (RightsE)Convert.ToInt32(rights[0]));
            if (rights.Length == 5)
            {
                _rights = new Rights(HelpRightsE(rights[0]), HelpRightsE(rights[1]), HelpRightsE(rights[2]), HelpRightsE(rights[3]), HelpRightsE(rights[4]));
            }
        }

        public Charackter(string name, int level, CharackterKlasse klasse, CharackterJob job, Rights rights, int mindex)
        {
            _name = name;
            _level = level;
            _klasse = klasse;
            _job = job;
            _rights = rights;
            _mindex = mindex;
        }

        public int Charcode
        {
            get { return (int)_klasse + (int)_job; }
            set
            {
                //Charackterklassen (9)
                for (int klasse = 0; klasse <= 144; klasse += 16)
                    //Jobs (9)
                    for (int job = 1; job <= 9; job++)
                        if (value == klasse + job)
                        {
                            _klasse = (CharackterKlasse)klasse;
                            _job = (CharackterJob)job;
                        }
            }
        }
    }
}
